using System;
using System.Collections.Generic;
using I2.Loc;
using UnityEngine;

public class ProfilePanelUI : MonoBehaviour
{
	[HideInInspector]
	public static ProfilePanelUI instance;

	[Header("Tab buttons")]
	public UIButton TabButton_General;

	public UIButton TabButton_Online;

	public UIButton TabButton_Offline;

	public UIButton TabButton_Achivments;

	[Header("Button sprites")]
	public string normalSprite = "BtnGray";

	public string selectedSprite = "BtnBlue";

	[Header("Tab wigets")]
	public GameObject Tab_General;

	public GameObject Tab_Online;

	public GameObject Tab_Offline;

	public GameObject Tab_Achivments;

	[Header("General UI ----------------------")]
	[Space(10f)]
	public UILabel hidenCoinsCountLabel1;

	public UILabel hidenCoinsCountLabel2;

	[Space(10f)]
	public UILabel totalTimePlayed1;

	public UILabel totalTimePlayed2;

	[Space(10f)]
	public UILabel cashEarned1;

	public UILabel cashEarned2;

	public UILabel cashSpent1;

	public UILabel cashSpent2;

	[Space(10f)]
	public UILabel jobsLabel1;

	public UILabel jobsLabel2;

	[Header("Online UI ----------------------")]
	public UISprite killsPvpShare;

	public UISprite killsSendboxShare;

	public UILabel killsPVPCountLabel;

	public UILabel killsSendboxCountLabel;

	public UILabel killsTotalCountLabel;

	[Space(10f)]
	public UISprite winsPvpShare;

	public UISprite winsSendboxShare;

	public UILabel winsPVPCountLabel;

	public UILabel winsSendboxCountLabel;

	public UILabel winsTotalCountLabel;

	[Space(10f)]
	public UISprite destroyedOnlineCarsShare;

	public UISprite destroyedOnlineTanksShare;

	public UISprite destroyedOnlineHelicoptersShare;

	public UISprite destroyedOnlineBoatsShare;

	public UISprite destroyedOnlineBikesShare;

	[Space(5f)]
	public UILabel destroyedOnlineCarsLabel;

	public UILabel destroyedOnlineTanksLabel;

	public UILabel destroyedOnlineHelicoptersLabel;

	public UILabel destroyedOnlineBoatsLabel;

	public UILabel destroyedOnlineBikesLabel;

	[Space(5f)]
	public UILabel playerIdLable1;

	public UILabel playerIdLable2;

	[Header("Offlone UI ----------------------")]
	public UISprite killdOfflineCopsShare;

	public UISprite killdOfflineCitizensShare;

	public UISprite killdOfflineBanditsShare;

	public UISprite killdOfflineZombiesShare;

	[Space(5f)]
	public UILabel killdOfflineCopsLabel;

	public UILabel killdOfflineCitizensLabel;

	public UILabel killdOfflineBanditsLabel;

	public UILabel killdOfflineZombiesLabel;

	[Space(10f)]
	public UISprite destroyedOfflineCarsShare;

	public UISprite destroyedOfflineTanksShare;

	public UISprite destroyedOfflineHelicoptersShare;

	public UISprite destroyedOfflineBoatsShare;

	public UISprite destroyedOfflineBikesShare;

	[Space(5f)]
	public UILabel destroyedOfflineCarsLabel;

	public UILabel destroyedOfflineTanksLabel;

	public UILabel destroyedOfflineHelicoptersLabel;

	public UILabel destroyedOfflineBoatsLabel;

	public UILabel destroyedOfflineBikesLabel;

	[Header("Achivments UI ----------------------")]
	private bool instantiateAchivmentPanels = true;

	private List<AchivmentProfilePanel> allAchivmentPanels = new List<AchivmentProfilePanel>();

	public GameObject achivmentsGrid;

	public GameObject achivmentProfileUIPrefab;

	private float currentFillAmount;

	private string language;

	private void Awake()
	{
		instance = this;
	}

	private void Start()
	{
		ShowTab_General();
		UpdateProfileUI();
	}

	public void UpdateProfileUI()
	{
		SetGeneralInfo();
		SetOnlineInfo();
		SetOfflineInfo();
		SetAchivmentsInfo();
	}

	public void ShowTab_General()
	{
		Tab_General.SetActive(true);
		TabButton_General.normalSprite = selectedSprite;
		Tab_Online.SetActive(false);
		TabButton_Online.normalSprite = normalSprite;
		Tab_Offline.SetActive(false);
		TabButton_Offline.normalSprite = normalSprite;
		Tab_Achivments.SetActive(false);
		TabButton_Achivments.normalSprite = normalSprite;
	}

	public void ShowTab_Online()
	{
		Tab_General.SetActive(false);
		TabButton_General.normalSprite = normalSprite;
		Tab_Online.SetActive(true);
		TabButton_Online.normalSprite = selectedSprite;
		Tab_Offline.SetActive(false);
		TabButton_Offline.normalSprite = normalSprite;
		Tab_Achivments.SetActive(false);
		TabButton_Achivments.normalSprite = normalSprite;
	}

	public void ShowTab_Offline()
	{
		Tab_General.SetActive(false);
		TabButton_General.normalSprite = normalSprite;
		Tab_Online.SetActive(false);
		TabButton_Online.normalSprite = normalSprite;
		Tab_Offline.SetActive(true);
		TabButton_Offline.normalSprite = selectedSprite;
		Tab_Achivments.SetActive(false);
		TabButton_Achivments.normalSprite = normalSprite;
	}

	public void ShowTab_Achivments()
	{
		Tab_General.SetActive(false);
		TabButton_General.normalSprite = normalSprite;
		Tab_Online.SetActive(false);
		TabButton_Online.normalSprite = normalSprite;
		Tab_Offline.SetActive(false);
		TabButton_Offline.normalSprite = normalSprite;
		Tab_Achivments.SetActive(true);
		TabButton_Achivments.normalSprite = selectedSprite;
	}

	private void SetGeneralInfo()
	{
		hidenCoinsCountLabel1.text = ProfileCounters.instance.coinsCollected + " / " + ProfileCounters.instance.coinsCount;
		hidenCoinsCountLabel2.text = hidenCoinsCountLabel1.text;
		totalTimePlayed1.text = ProfileCounters.instance.totalTimePlayed.ToString();
		totalTimePlayed2.text = totalTimePlayed1.text;
		cashEarned1.text = ProfileCounters.instance.allEarnedCash.ToString();
		cashEarned2.text = cashEarned1.text;
		cashSpent1.text = ProfileCounters.instance.allSpentCash.ToString();
		cashSpent2.text = cashSpent1.text;
		jobsLabel1.text = ProfileCounters.instance.comletedMissions + " / " + ProfileCounters.instance.allMissions;
		jobsLabel2.text = jobsLabel1.text;
		playerIdLable1.text = BCWServer.idPlayer;
		playerIdLable2.text = playerIdLable1.text;
	}

	private void SetOnlineInfo()
	{
		killsPVPCountLabel.text = ProfileCounters.instance.PVPKills.ToString();
		killsSendboxCountLabel.text = ProfileCounters.instance.SendboxKills.ToString();
		int num = ProfileCounters.instance.PVPKills + ProfileCounters.instance.SendboxKills;
		currentFillAmount = 0f;
		SetShare(killsPvpShare, ProfileCounters.instance.PVPKills, num);
		SetShare(killsSendboxShare, ProfileCounters.instance.SendboxKills, num);
		killsTotalCountLabel.text = num.ToString();
		winsPVPCountLabel.text = ProfileCounters.instance.PVPWins.ToString();
		winsSendboxCountLabel.text = ProfileCounters.instance.SendboxWins.ToString();
		int num2 = ProfileCounters.instance.PVPWins + ProfileCounters.instance.SendboxWins;
		currentFillAmount = 0f;
		SetShare(winsPvpShare, ProfileCounters.instance.PVPWins, num2);
		SetShare(winsSendboxShare, ProfileCounters.instance.SendboxWins, num2);
		winsTotalCountLabel.text = num2.ToString();
		destroyedOnlineCarsLabel.text = ProfileCounters.instance.destroyedOnlineCars.ToString();
		destroyedOnlineTanksLabel.text = ProfileCounters.instance.destroyedOnlineTanks.ToString();
		destroyedOnlineHelicoptersLabel.text = ProfileCounters.instance.destroyedOnlineHelicopters.ToString();
		destroyedOnlineBoatsLabel.text = ProfileCounters.instance.destroyedOnlineBoats.ToString();
		destroyedOnlineBikesLabel.text = ProfileCounters.instance.destroyedOnlineBikes.ToString();
		int num3 = ProfileCounters.instance.destroyedOnlineCars + ProfileCounters.instance.destroyedOnlineTanks + ProfileCounters.instance.destroyedOnlineHelicopters + ProfileCounters.instance.destroyedOnlineBoats + ProfileCounters.instance.destroyedOnlineBikes;
		currentFillAmount = 0f;
		SetShare(destroyedOnlineCarsShare, ProfileCounters.instance.destroyedOnlineCars, num3);
		SetShare(destroyedOnlineTanksShare, ProfileCounters.instance.destroyedOnlineTanks, num3);
		SetShare(destroyedOnlineHelicoptersShare, ProfileCounters.instance.destroyedOnlineHelicopters, num3);
		SetShare(destroyedOnlineBoatsShare, ProfileCounters.instance.destroyedOnlineBoats, num3);
		SetShare(destroyedOnlineBikesShare, ProfileCounters.instance.destroyedOnlineBikes, num3);
	}

	private void SetOfflineInfo()
	{
		destroyedOfflineCarsLabel.text = ProfileCounters.instance.destroyedOfflineCars.ToString();
		destroyedOfflineTanksLabel.text = ProfileCounters.instance.destroyedOfflineTanks.ToString();
		destroyedOfflineHelicoptersLabel.text = ProfileCounters.instance.destroyedOfflineHelicopters.ToString();
		destroyedOfflineBoatsLabel.text = ProfileCounters.instance.destroyedOfflineBoats.ToString();
		destroyedOfflineBikesLabel.text = ProfileCounters.instance.destroyedOfflineBikes.ToString();
		int num = ProfileCounters.instance.destroyedOfflineCars + ProfileCounters.instance.destroyedOfflineTanks + ProfileCounters.instance.destroyedOfflineHelicopters + ProfileCounters.instance.destroyedOfflineBoats + ProfileCounters.instance.destroyedOfflineBikes;
		currentFillAmount = 0f;
		SetShare(destroyedOfflineCarsShare, ProfileCounters.instance.destroyedOfflineCars, num);
		SetShare(destroyedOfflineTanksShare, ProfileCounters.instance.destroyedOfflineTanks, num);
		SetShare(destroyedOfflineHelicoptersShare, ProfileCounters.instance.destroyedOfflineHelicopters, num);
		SetShare(destroyedOfflineBoatsShare, ProfileCounters.instance.destroyedOfflineBoats, num);
		SetShare(destroyedOfflineBikesShare, ProfileCounters.instance.destroyedOfflineBikes, num);
		killdOfflineCopsLabel.text = ProfileCounters.instance.killdOfflineCops.ToString();
		killdOfflineCitizensLabel.text = ProfileCounters.instance.killdOfflineCitizens.ToString();
		killdOfflineBanditsLabel.text = ProfileCounters.instance.killdOfflineBandits.ToString();
		killdOfflineZombiesLabel.text = ProfileCounters.instance.killdOfflineZombies.ToString();
		int num2 = ProfileCounters.instance.killdOfflineCops + ProfileCounters.instance.killdOfflineCitizens + ProfileCounters.instance.killdOfflineBandits + ProfileCounters.instance.killdOfflineZombies;
		currentFillAmount = 0f;
		SetShare(killdOfflineCopsShare, ProfileCounters.instance.killdOfflineCops, num2);
		SetShare(killdOfflineCitizensShare, ProfileCounters.instance.killdOfflineCitizens, num2);
		SetShare(killdOfflineBanditsShare, ProfileCounters.instance.killdOfflineBandits, num2);
		SetShare(killdOfflineZombiesShare, ProfileCounters.instance.killdOfflineZombies, num2);
	}

	private void SetShare(UISprite shareSprite, float count, float totalSum)
	{
		if (totalSum > 0f)
		{
			float num = count / totalSum;
			currentFillAmount += num;
			shareSprite.fillAmount = currentFillAmount;
		}
		else
		{
			shareSprite.fillAmount = 0f;
		}
	}

	private void SetAchivmentsInfo()
	{
		if (instantiateAchivmentPanels)
		{
			language = LocalizationManager.CurrentLanguage;
			List<Achievement> list = new List<Achievement>();
			List<Achievement> list2 = new List<Achievement>();
			List<Achievement> list3 = new List<Achievement>();
			foreach (Achievement allAchievement in AchievementsManager.instanse.allAchievements)
			{
				if (allAchievement.achieved)
				{
					list.Add(allAchievement);
				}
				else if (allAchievement.currentCount > 0)
				{
					list2.Add(allAchievement);
				}
				else
				{
					list3.Add(allAchievement);
				}
			}
			list.Sort((Achievement a, Achievement b) => a.sortIndex.CompareTo(b.sortIndex));
			list2.Sort((Achievement a, Achievement b) => ((float)a.neededCount / (float)a.currentCount).CompareTo((float)b.neededCount / (float)b.currentCount));
			list3.Sort((Achievement a, Achievement b) => a.sortIndex.CompareTo(b.sortIndex));
			foreach (Achievement item in list)
			{
				InstantiateProfileAchivment(item);
			}
			foreach (Achievement item2 in list2)
			{
				InstantiateProfileAchivment(item2);
			}
			foreach (Achievement item3 in list3)
			{
				InstantiateProfileAchivment(item3);
			}
			instantiateAchivmentPanels = false;
			return;
		}
		bool initProgressOnly = string.Equals(language, LocalizationManager.CurrentLanguage);
		foreach (AchivmentProfilePanel allAchivmentPanel in allAchivmentPanels)
		{
			allAchivmentPanel.achivmentCount.text = allAchivmentPanel.achievement.currentCount + "/" + allAchivmentPanel.achievement.neededCount;
			allAchivmentPanel.Init(allAchivmentPanel.achievement, initProgressOnly);
		}
		language = LocalizationManager.CurrentLanguage;
	}

	private void InstantiateProfileAchivment(Achievement achivment)
	{
		GameObject gameObject = NGUITools.AddChild(achivmentsGrid, achivmentProfileUIPrefab);
		AchivmentProfilePanel component = gameObject.GetComponent<AchivmentProfilePanel>();
		component.Init(achivment);
		allAchivmentPanels.Add(component);
	}

	private void Update()
	{
		double value = ProfileCounters.instance.totalTimePlayed + (double)Time.time - settings.thisScript.savedPlayTime;
		TimeSpan timeSpan = TimeSpan.FromSeconds(value);
		totalTimePlayed1.text = string.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
		totalTimePlayed2.text = totalTimePlayed1.text;
	}
}
